package com.cskaoyan.gateway.controller.user;

import com.mall.commons.result.ResponseData;
import com.mall.commons.result.ResponseUtil;
import com.mall.commons.tool.utils.CookieUtil;
import com.mall.user.IKaptchaService;
import com.mall.user.UserSerivce;
import com.mall.user.annotation.Anoymous;
import com.mall.user.constants.SysRetCodeConstants;
import com.mall.user.dto.*;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by 郭浩 on 2020/11/16 15:01
 */
@RestController
@RequestMapping("user")
@Anoymous
public class RegisterController {

    @Reference(interfaceClass = UserSerivce.class,check = false,retries = 0)
    UserSerivce userService;
    @Reference(interfaceClass = UserSerivce.class,check = false,retries = 0)
    IKaptchaService iKaptchaService;

    @PostMapping("register")
    public ResponseData register(@RequestBody UserRegisterRequest req, HttpServletRequest httpServletRequest) {
        //验证验证码
//        KaptchaCodeRequest kaptchaCodeRequest = new KaptchaCodeRequest();
//        kaptchaCodeRequest.setCode(req.getCaptcha());
//        kaptchaCodeRequest.setUuid(CookieUtil.getCookieValue(httpServletRequest,"kaptcha_uuid"));
//        KaptchaCodeResponse kaptchaCodeResponse = iKaptchaService.validateKaptchaCode(kaptchaCodeRequest);
//
//        if (!SysRetCodeConstants.SUCCESS.getCode().equals(kaptchaCodeResponse.getCode())){
//            return new ResponseUtil<>().setErrorMsg(kaptchaCodeResponse.getMsg());
//        }
        //注册
        UserRegisterResponse userRegisterResponse = userService.register(req);


        return new ResponseUtil<>().setData(userRegisterResponse);
    }

    @GetMapping("verify")
    public ResponseData verifyUser(String uid,String username){
        UserVerifyResponse verify = userService.verify(uid, username);
        ResponseData<Object> objectResponseData = new ResponseUtil<>().setData(verify);
        return objectResponseData;
    }
}
